package com.martin.study.depend_inject.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MineInstantiationAwareBeanPostProcessor implements InstantiationAwareBeanPostProcessor {

	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		if(beanName.equals("standardBean")){
			System.out.println("实例化前......");
//			return new LifeCycleTestBean();
		}
		return null;
	}

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		if(beanName.equals("standardBean")){
			System.out.println("实例化后......");
		}
		//如果返回false，可中断依赖注入
		return false;
	}

	@Override
	public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
		if(beanName.equals("standardBean")){
			System.out.println("始化前依赖注入回调，可自定义实现属性注入......");
		}
		return pvs;
	}
}
